package cn.wmx.boot;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

public class MyWebApplicationInitializer implements WebApplicationInitializer {
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        System.out.println("咱也不知道这个又是啥鬼东西，咱先仿照着抄一下…… ");
        // 通过注解的方式初始化 spring 上下文
        AnnotationConfigWebApplicationContext ac = new AnnotationConfigWebApplicationContext();
        // 看到这里把 AppConfig 当作入参，似乎明白了些什么，，，
        ac.register(AppConfig.class);

        // 抄着抄着就来了感觉
        DispatcherServlet ds = new DispatcherServlet(ac);
        ServletRegistration.Dynamic dynamic = servletContext.addServlet("/", ds);
        dynamic.setLoadOnStartup(1);
        dynamic.addMapping("/*");

        // 好像明白了些什么，但是好像又没懂  ？！？！？！？！？

    }
}
